package com.example.sofa_module.sofa.fragments.video;

import android.view.View;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;

import com.alibaba.android.arouter.launcher.ARouter;
import com.example.baserecyclerview.quick.BaseQuickAdapter;
import com.example.common.mvvm.view.BaseFragment;
import com.example.sofa_module.databinding.FragmentSofachildBinding;
import com.example.sofa_module.sofa.entity.BeanEntity;
import com.example.sofa_module.sofa.fragments.pics.ChildAdapter;
import com.example.sofa_module.sofa.fragments.pics.ChildViewModel;

import java.util.List;

public class Fragment_video extends BaseFragment<FragmentSofachildBinding, VideoViewModel> implements BaseQuickAdapter.OnItemClickListener {

    private  VideoAdapter videoAdapter;

    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBinding() {
        FragmentSofachildBinding fragmentSofachildBinding=FragmentSofachildBinding.inflate(inflater);
        return fragmentSofachildBinding;
    }
    @Override
    public void initView() {
        videoAdapter= new VideoAdapter();
        videoAdapter.setOnItemClickListener(this);
    }
    @Override
    public void initData() {
      vm.sofa_list.observe(this, new Observer<List<BeanEntity>>() {
          @Override
          public void onChanged(List<BeanEntity> beanEntities) {
              v.SofaRe.setLayoutManager(new LinearLayoutManager(getContext()));
              v.SofaRe.setAdapter(videoAdapter);
              videoAdapter.setNewInstance(beanEntities);
          }
      });
    }

    @Override
    public void onItemClick(RecyclerView.Adapter adapter, int possition) {
        if (adapter instanceof VideoAdapter){
            VideoAdapter videoAdapter = (VideoAdapter) adapter;
            BeanEntity beanEntity = videoAdapter.getData().get(possition);
            ARouter.getInstance().build("/sofa/deatailsactivity")
                    .withSerializable("beanEntity",beanEntity)
                    .navigation();
        }
    }
}
